package com.leps.nq.common;

import com.leps.nq.common.util.FileUploadUtils;
import com.leps.nq.common.vo.R;
import com.leps.nq.common.vo.RBuilder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

@RestController
@Api(tags = "通用文件上传接口")
public class FileUploadController {
    @ApiOperation("上传单个文件")
    @PostMapping("/fileupload/single")
    public R uploadSingleFile(MultipartFile file) {
        String filename = FileUploadUtils.upload(file);
        return RBuilder.ok(filename);
    }
    @ApiOperation("上传多个文件")
    @PostMapping("/fileupload/multi")
    public R uploadSingleFile(MultipartFile[] files) {
        List<String> filenames = new ArrayList<>();
        for (MultipartFile file : files) {
            String filename = FileUploadUtils.upload(file);
            filenames.add(filename);
        }
        return RBuilder.ok(filenames);
    }
}
